//#pragma once
#ifndef __COMM_HPP__
#define __COMM_HPP__
#include <iostream>
#include <string>
#include <cstdio>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/shm.h>
#include <cstring>
#include <fcntl.h>

#define SIZE 4096
#define PROJ_ID 0X66666
const std::string PATHNAME = "/home/zyx/code";

key_t Get_Key()
{
    key_t key = ftok(PATHNAME.c_str(), PROJ_ID);
    if(key < 0)
    {
        perror("comm.hpp::Get_Key::ftok");
        exit(0);
    }

    return key;
}

int GetSharememHelper(int flag)
{
    //umask(0);

    int shmid = shmget(Get_Key(), SIZE, flag);
    if(shmid < 0)
    {
        perror("comm.hpp::GetSharememHelper::shmget");
        exit(0);
    }

    return shmid;
}

int CreateShm()
{
    return GetSharememHelper(IPC_CREAT | IPC_EXCL | 0666);
}

int GetShm()
{
    return GetSharememHelper(IPC_CREAT);
}

#endif